package com.bupt.controller;

import com.bupt.bean.DeviceTypeAttribute;
import com.bupt.bean.DeviceTypeAttributeSub;
import com.bupt.config.DeviceTypeAttributeResult;
import com.bupt.config.DeviceTypeAttributeSubResult;
import com.bupt.config.Result;
import com.bupt.service.DeviceService;
import com.bupt.vo.SysConst;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value="设备子属性配置",description="设备子属性的增删改查和属性类型")
@RestController
public class DeviceTypeAttributeSubController {

    @Autowired
    private DeviceService deviceService;


    @ApiImplicitParams({@ApiImplicitParam(name = "deviceTypeId", value = "设备类型ID", required = true, paramType = "path", dataType = "int")})
    @ApiOperation("根据设备类型ID查询设备子属性")
    @GetMapping("/deviceTypeAttributeSubPage/{deviceTypeId}")
    public List deviceTypeAttributeSubPage(@PathVariable("deviceTypeId") Integer deviceTypeId) {
        return deviceService.findDeviceTypeAttributeSubList(deviceTypeId);
    }

    @ApiOperation("添加设备子属性")
    @PutMapping("/deviceTypeAttributeSub/{deviceTypeId}")
    public DeviceTypeAttributeSubResult addDeviceTypeAttributeSub(@PathVariable("deviceTypeId") Integer deviceTypeId, @RequestBody DeviceTypeAttributeSub deviceTypeAttributeSub) {
        return deviceService.addDeviceTypeAttributeSub(deviceTypeId,deviceTypeAttributeSub);
    }

    @ApiOperation("通过ID删除设备子属性")
    @DeleteMapping("/deviceTypeAttributeSub/deleteById/{deviceTypeAttributeSubId}")
    public Result deviceTypeAttributeSub(@PathVariable("deviceTypeAttributeSubId") Integer deviceTypeAttributeSubId) {
        return deviceService.deleteDeviceTypeAttributeSubById(deviceTypeAttributeSubId);
    }
    @ApiOperation("通过ID修改设备子属性")
    @PostMapping("/deviceTypeAttributeSub/edit/{deviceTypeAttributeSubId}")
    public DeviceTypeAttributeSubResult editDeviceTypeAttributeSub(@PathVariable("deviceTypeAttributeSubId") Integer deviceTypeAttributeSubId,@RequestBody DeviceTypeAttributeSub deviceTypeAttributeSub) {
        return deviceService.editDeviceTypeAttributeSub(deviceTypeAttributeSubId,deviceTypeAttributeSub);
    }
    @ApiOperation("属性类型")
    @GetMapping("/deviceTypeAttributeSub/attributeType")
    public List<SysConst> attributeType() {
        return deviceService.attributeTypeSub();
    }

}
